package com.zy.controller;

import com.zy.entity.User;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LittleDesire
 * @description
 * @date 2022-03-31 周四 17:34
 * @since 17
 */
@Controller

public class TestController {
    @RequestMapping
    public String t1() {
        return "home";
    }



    @RequestMapping("/api/show")
    @ResponseBody
    @CrossOrigin
    public Map<String, Object> show(User user, HttpServletRequest req) {
        System.out.println(user);
        System.out.println(req.getMethod());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("method", req.getMethod());
        map.put("ip", req.getRemoteAddr());
        map.put("data", user);
        return map;
    }


    @RequestMapping("/api/p")
    @ResponseBody
    @CrossOrigin
    public Map<String, Object> show1(@RequestBody User user, HttpServletRequest req) {
        System.out.println(user);
        System.out.println(req.getMethod());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("method", req.getMethod());
        map.put("ip", req.getRemoteAddr());
        map.put("data", user);
        map.put("msg", "post成功");
        return map;
    }


    @RequestMapping("/api/p2")
    @ResponseBody
    @CrossOrigin
    public Map<String, Object> show2(User user, Integer c,HttpServletRequest req) {
        System.out.println(user);
        System.out.println(req.getMethod());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("method", req.getMethod());
        map.put("ip", req.getRemoteAddr());
        map.put("data", user);
        map.put("c", c);
        map.put("msg", "post成功");
        return map;
    }

    @PutMapping("/api/p3")
    @ResponseBody
    @CrossOrigin
    public Map<String, Object> show3( User user,  Integer c,HttpServletRequest req) {
        System.out.println(user);
        System.out.println(req.getMethod());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("method", req.getMethod());
        map.put("ip", req.getRemoteAddr());
        map.put("data", user);
        map.put("c", c);
        map.put("msg", "put成功");
        return map;
    }

    @DeleteMapping("/api/d")
    @ResponseBody
    @CrossOrigin
    public Map<String, Object> show4( User user,  Integer c,HttpServletRequest req) {
        System.out.println(user);
        System.out.println(req.getMethod());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("method", req.getMethod());
        map.put("ip", req.getRemoteAddr());
        map.put("data", user);
        map.put("c", c);
        map.put("msg", "put成功");
        return map;
    }


    @PatchMapping("/api/patch")
    @ResponseBody
    @CrossOrigin
    public Map<String, Object> show5( @RequestBody User user,  Integer c,HttpServletRequest req) {
        System.out.println(user);
        System.out.println(req.getMethod());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("method", req.getMethod());
        map.put("ip", req.getRemoteAddr());
        map.put("data", user);
        map.put("c", c);
        map.put("msg", "put成功");
        return map;
    }
}
